
#include"customdb_operator.h"
#include<vector>
#include<string>
#include <sstream>

using namespace std;
/// splite string with black
//typedef bool (CCustomOperator::* FUNC)(vector<string>& command_args);
//map<string,FUNC> function_mapping;
//typedef bool (*FUNC)(vector<string>& command_args);

void splite_string(string & command ,vector<string>& command_args)
{
    string arg;
    istringstream f(command.c_str());
    while (std::getline(f, arg, ' '))
    {
        command_args.push_back(arg);
    }
}

void deal_command(CCustomOperator &customerOperator,vector<string>& command_args)
{
    int args=command_args.size();
    //map<string,FUNC>::iterator it;
    //it=function_mapping.find(command_args[0]);
   //FUNC f= it->second;
    //(CCustomOperator::*f)(command_args);
  //if(!strcmp(argv[1],"add-member"))
    if(command_args[0]=="add-member")
    {
        //add member to db
        //customerOperator.addMember(command_args[1],command_args[2],command_args[3]);
        customerOperator.addMember(command_args);
        return;
    }
     //if(!strcmp(argv[1],"add-card"))
        if(command_args[0]=="add-card")
        {
            //bind menber with card
           /* if(command_args.size()==5)
            **{
            *    customerOperator.addCard(command_args[1],command_args[2],command_args[3]);
            *}
            *else
             **   customerOperator.addCard(command_args[1],command_args[2]);*/
               customerOperator.addCard(command_args);
               return;
        }
   if(command_args[0]=="add-course")
    {
        //add member to db
        //customerOperator.addMember(command_args[1],command_args[2],command_args[3]);
        customerOperator.addCourse(command_args);
        return;
    }
       if(command_args[0]=="add-coach")
    {
        //add member to db
        //customerOperator.addMember(command_args[1],command_args[2],command_args[3]);
        customerOperator.addCoach(command_args);
        cout<<"";
        return;
    }
       if(command_args[0]=="schedule")
    {
        //add member to db
        //customerOperator.addMember(command_args[1],command_args[2],command_args[3]);
        customerOperator.schedule(command_args);
        return;
    }
       if(command_args[0]=="subscribe")
    {
        //add member to db
        //customerOperator.addMember(command_args[1],command_args[2],command_args[3]);
        customerOperator.subscribe(command_args);
        return;
    }
          if(command_args[0]=="cancel")
    {
        //add member to db
        //customerOperator.addMember(command_args[1],command_args[2],command_args[3]);
        customerOperator.cancel(command_args);
        return;
    }

           cout<<"error,usage:..."<<endl ;



}


int main()
{
    CCustomOperator customerOperator;

 /*function_mapping.insert(map<string,FUNC>::value_type("add-member",customerOperator.addMember));
  function_mapping.insert(map<string,FUNC>::value_type("add-card",customerOperator.addCard));
  function_mapping.insert(map<string,FUNC>::value_type("add-course",customerOperator.addCourse));
  function_mapping.insert(map<string,FUNC>::value_type("add-coach",customerOperator.addCoach));
  function_mapping.insert(map<string,FUNC>::value_type("schedule",customerOperator.schedule));
  function_mapping.insert(map<string,FUNC>::value_type("subscribe",customerOperator.subscribe)));
  function_mapping.insert(map<string,FUNC>::value_type("cancel",customerOperator.cancel));*/
    while(1)
    {
        cout<<">iyoga ";
        string command;
        getline(cin,command);
        vector<string> command_args;
        splite_string(command,command_args);
        int args=command_args.size();


    deal_command(customerOperator,command_args);
    }
    return 0;
}
